package br.com.foxinline.modelo;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.DecimalMin;

/**
 *
 * @author cadomeireles
*/
@Entity
public class Saida implements Serializable{

    @Id
    @SequenceGenerator(name = "seq_saida", sequenceName = "seq_saida",allocationSize = 1)
    @GeneratedValue(generator = "seq_saida", strategy = GenerationType.SEQUENCE)
    private Long id;

    private boolean ativo;

    @OneToOne
    private TipoSaida tipoSaida;

    @Column(scale = 2, precision = 14)
    @DecimalMin(value = "0.00")
    private BigDecimal valor;

    @Temporal(TemporalType.DATE)
    private Date dataSaida;

    @Temporal(TemporalType.DATE)
    private Date dataCadastro;    
    
    @OneToOne
    private Usuario usuario;
    
    private String descricao;

    public Saida() {
        this.ativo = true;
        this.dataCadastro = new Date();
    }   

    public Saida(Long id, TipoSaida tipoSaida, BigDecimal valor, Date dataSaida, Usuario usuario, String descricao) {
        this.id = id;
        this.ativo = true;
        this.tipoSaida = tipoSaida;
        this.valor = valor;
        this.dataSaida = dataSaida;
        this.dataCadastro = new Date();
        this.usuario = usuario;
        this.descricao = descricao;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public boolean isAtivo() {
        return ativo;
    }

    public void setAtivo(boolean ativo) {
        this.ativo = ativo;
    }

    public TipoSaida getTipoSaida() {
        return tipoSaida;
    }

    public void setTipoSaida(TipoSaida tipoSaida) {
        this.tipoSaida = tipoSaida;
    }

    public BigDecimal getValor() {
        return valor;
    }

    public void setValor(BigDecimal valor) {
        this.valor = valor;
    }

    public Date getDataSaida() {
        return dataSaida;
    }

    public void setDataSaida(Date dataSaida) {
        this.dataSaida = dataSaida;
    }

    public Date getDataCadastro() {
        return dataCadastro;
    }

    public void setDataCadastro(Date dataCadastro) {
        this.dataCadastro = dataCadastro;
    }

    public Usuario getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    public String getDescricao() {
        return descricao;
    }

    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 29 * hash + (this.id != null ? this.id.hashCode() : 0);
        hash = 29 * hash + (this.ativo ? 1 : 0);
        hash = 29 * hash + (this.tipoSaida != null ? this.tipoSaida.hashCode() : 0);
        hash = 29 * hash + (this.valor != null ? this.valor.hashCode() : 0);
        hash = 29 * hash + (this.dataSaida != null ? this.dataSaida.hashCode() : 0);
        hash = 29 * hash + (this.dataCadastro != null ? this.dataCadastro.hashCode() : 0);
        hash = 29 * hash + (this.usuario != null ? this.usuario.hashCode() : 0);
        hash = 29 * hash + (this.descricao != null ? this.descricao.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Saida other = (Saida) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        if (this.ativo != other.ativo) {
            return false;
        }
        if (this.tipoSaida != other.tipoSaida && (this.tipoSaida == null || !this.tipoSaida.equals(other.tipoSaida))) {
            return false;
        }
        if (this.valor != other.valor && (this.valor == null || !this.valor.equals(other.valor))) {
            return false;
        }
        if (this.dataSaida != other.dataSaida && (this.dataSaida == null || !this.dataSaida.equals(other.dataSaida))) {
            return false;
        }
        if (this.dataCadastro != other.dataCadastro && (this.dataCadastro == null || !this.dataCadastro.equals(other.dataCadastro))) {
            return false;
        }
        if (this.usuario != other.usuario && (this.usuario == null || !this.usuario.equals(other.usuario))) {
            return false;
        }
        if ((this.descricao == null) ? (other.descricao != null) : !this.descricao.equals(other.descricao)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Saida{" + "id=" + id + ", ativo=" + ativo + ", tipoSaida=" + tipoSaida + ", valor=" + valor + ", dataSaida=" + dataSaida + ", dataCadastro=" + dataCadastro + ", usuario=" + usuario + ", descricao=" + descricao + '}';
    }

}
